--[[
Name: archaeologyJournal
Author: Sonora (The Dragonflight, US Kirin Tor)
Website & SVN:  http://wow.curseforge.com/addons/archaeologyjournal/
License: GNU General Public License v3
]]

--Utilities
local function deepcopy(object)
    local lookup_table = {}
    local function _copy(object)
        if type(object) ~= "table" then
            return object
        elseif lookup_table[object] then
            return lookup_table[object]
        end
        local new_table = {}
        lookup_table[object] = new_table
        for index, value in pairs(object) do
            new_table[_copy(index)] = _copy(value)
        end
        return setmetatable(new_table, _copy(getmetatable(object)))
    end
    return _copy(object)
end

local AceConfig = LibStub("AceConfig-3.0")
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
archaeologyJournal = LibStub("AceAddon-3.0"):NewAddon("archaeologyJournal", "AceComm-3.0", "AceSerializer-3.0", "AceEvent-3.0", "AceHook-3.0")

function archaeologyJournal:OnInitialize()
    
    --Load the blizzard UI so we can inject ourselves
    LoadAddOn("Blizzard_ArchaeologyUI")
    
    --Addon wide data structures
    
    --Setup a default profile table for the database
    local defaultProfileDb = {
        profile = {
            config = deepcopy(self.defaultConfig)
        }
    }
    
    --Setup data base communication    
    self.db = LibStub("AceDB-3.0"):New("archaeologyJournalDb", defaultProfileDb)
    self.db.RegisterCallback(self, "OnProfileChanged", "OnProfileChanged")
    
    --This call in turn handles changes to archaeologyJournal.config and config GUI construction
    self:OnProfileChanged(nil, self.db, self.db:GetCurrentProfile())
    
    --Register us as recievers of our AceComm messages
    --self:RegisterComm('message', 'method')
    
    --Event handlers
    --self:RegisterEvent('event')
    
    --Setup the user interface, and fire events which don't on their own at log in
    self:buildUI()
    
end

function archaeologyJournal:buildUI()

    ArchaeologyFrame:Show()

    --Inject UI into default archaeology UI
    self:injectLogTab()
    
end

function archaeologyJournal:OnProfileChanged(eventName, db, newProfile)
    self.config = db.profile.config
    self:updateConfig()
end

function archaeologyJournal:updateConfig()

end


--[[
Notes:  

1) steal professions tab UI layout
2) Add button to archaeology section

GetPlayerFacing() - Returns the direction the player is facing in radians ([-π, π] range, 0 is north, π/2 is east). (3.1)

ArchaeologyGetIconInfo
ArchaeologyMapUpdateAll

GetArchaeologyInfo
GetArchaeologyRaceInfo

GetArtifactInfoByRace
GetArtifactProgress

GetNumArchaeologyRaces
GetNumArtifactsByRace

CanItemBeSocketedToArtifact
CanSolveArtifact

GetActiveArtifactByRace
GetArtifactInfoByRace
GetArtifactProgress

GetNumArtifactsByRace
GetSelectedArtifactInfo

IsArtifactCompletionHistoryAvailable
ItemAddedToArtifact
RemoveItemFromArtifact

RequestArtifactCompletionHistory

SetSelectedArtifact
SocketItemToArtifact
SolveArtifact

EVENTS
ARCHAEOLOGY_CLOSED
ARCHAEOLOGY_TOGGLE
ARTIFACT_COMPLETE
ARTIFACT_DIG_SITE_UPDATED
ARTIFACT_HISTORY_READY
ARTIFACT_UPDATE
]]--